class Gate:
    def __init__(self, k, n) -> None:
        self.k = k
        self.n = n

    def __str__(self):
        return f'({self.k}, {self.n})'

class Node:
    def __init__(self, gate, children, attr) -> None:
        self.gate = gate
        self.children = children
        self.attr = attr
        self.secret = None

    @staticmethod
    def threshold_node(gate, children):
        return Node(gate, children, None)

    @staticmethod
    def attr_node(attr):
        return Node(None, None, attr)

    def is_leaf(self):
        return self.gate is None

    def __dfs(self, deep):
        s = '\t' * deep
        if self.is_leaf():
            s += str(self.attr) + f': {self.secret}' + '\n'
        else:
            s += str(self.gate) + f': {self.secret}' + '\n'
            for c in self.children:
                s += c.__dfs(deep + 1)
        return s

    def __str__(self):
        return self.__dfs(0)
